home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / execview < prev    next >
Text File  |  1996-07-15  |  2KB  |  81 lines

  1. /* ----------------------------------------------------------------------
  2.    Execute the given mailcap command
  3.  
  4.   Args: cmd           -- the command to execute
  5.     image_file    -- the file the data is in
  6.     needsterminal -- does this command want to take over the terminal?
  7.   ----*/
  8. void
  9. exec_mailcap_cmd(cmd, image_file, needsterminal)
  10. char *cmd;
  11. char *image_file;
  12. int   needsterminal;
  13. {
  14.     char   *command = NULL,
  15.        *result_file = NULL,
  16.        *p;
  17.     char  **r_file_h;
  18.     PIPE_S *syspipe;
  19.     int     mode;
  20.  
  21.     p = command = (char *)fs_get((32 + strlen(cmd) + (2*strlen(image_file)))
  22.                  * sizeof(char));
  23.     if(!needsterminal)  /* put in background if it doesn't need terminal */
  24.       *p++ = '(';
  25.     sprintf(p, "%s ; rm -f %s", cmd, image_file);
  26.     p += strlen(p);
  27.     if(!needsterminal){
  28.     *p++ = ')';
  29.     *p++ = ' ';
  30.     *p++ = '&';
  31.     }
  32.     *p++ = '\n';
  33.     *p   = '\0';
  34.     dprint(9, (debugfile, "exec_mailcap_cmd: command=%s\n", command));
  35.  
  36.     mode = PIPE_RESET;
  37.     if(needsterminal == 1)
  38.       r_file_h = NULL;
  39.     else{
  40.     mode       |= PIPE_WRITE | PIPE_STDERR;
  41.     result_file = temp_nam(NULL, "pine_cmd");
  42.     r_file_h    = &result_file;
  43.     }
  44.  
  45.     if(syspipe = open_system_pipe(command, r_file_h, NULL, mode)){
  46.     close_system_pipe(&syspipe);
  47.     if(needsterminal == 1)
  48.       q_status_message(SM_ORDER, 0, 4, "VIEWER command completed");
  49.     else if(needsterminal == 2)
  50.       display_output_file(result_file, "VIEWER", " command result");
  51.     else
  52.       display_output_file(result_file, "VIEWER", " command launched");
  53.     }
  54.     else
  55.       q_status_message1(SM_ORDER, 3, 4, "Cannot spawn command : %s", cmd);
  56.  
  57.     fs_give((void **)&command);
  58.     if(result_file)
  59.       fs_give((void **)&result_file);
  60. }
  61.  
  62.  
  63. /* ----------------------------------------------------------------------
  64.    Execute the given mailcap test= cmd
  65.  
  66.   Args: cmd -- command to execute
  67.   Returns exit status
  68.   
  69.   ----*/
  70. int
  71. exec_mailcap_test_cmd(cmd)
  72.     char *cmd;
  73. {
  74.     PIPE_S *syspipe;
  75.  
  76.     return((syspipe = open_system_pipe(cmd, NULL, NULL, PIPE_SILENT))
  77.          ? close_system_pipe(&syspipe) : -1);
  78. }
  79.  
  80.  
  81.